package com.txcb.lib.base.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.txcb.lib.base.R;

/**
 * author Lambert on 2019/10/25
 */
public class LoadingDialog extends Dialog {

    private View contentView;

    private Context mContext;

    private TextView mTv1;
    private ImageView mImgLoad;

    private String mContent;
    private AnimationDrawable animationDrawable;


    public LoadingDialog(Context context, String content) {
        super(context, R.style.LoadingDialog);

        mContext = context;
        mContent = content;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();
    }

    private void initView() {
        if (contentView == null) {
            contentView = LayoutInflater.from(mContext).inflate(R.layout.layout_dialog_load, null);
        }

        if (mTv1 == null) {
            mTv1 = contentView.findViewById(R.id.id_dialog_load_tv_message);
        }

        if (mImgLoad == null) {
            mImgLoad = contentView.findViewById(R.id.id_dialog_load_img);
        }


        if (!TextUtils.isEmpty(mContent)) {
            mTv1.setText(mContent);
        }

        animationDrawable = (AnimationDrawable) mImgLoad.getDrawable();
        animationDrawable.start();

        setContentView(contentView);
    }


    public void setDialogContent(String content) {
        try {
            if (mTv1 != null) {
                mTv1.setText(content);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
